<?php
//定义该页面使用的php函数
function filter_property_selected($property_id,$sku_property,$class='checked',$nonclass='')
{
    if(empty($sku_property)){
        return $nonclass;
    }
    if(isset($sku_property[$property_id])){
        return $class;
    }
    return $nonclass;
}

function filter_proval_selected($property_id,$propval_id,$sku_property,$class='checked',$nonclass='')
{
    if(empty($sku_property)){
        return $nonclass;
    }
    if(!isset($sku_property[$property_id])){
        return $nonclass;
    }
    if(in_array($propval_id,$sku_property[$property_id])){
        return $class;
    }
    return $nonclass;
}
?>
<div class="form-control-box">

    <div class="goods-spec w800" data-anchor="商品规格">
        <div class="simple-form-field spec-title-box" style="position:relative">
            <div class="form-group">
                <label class="col-sm-2 control-label w100">商品规格：</label>
                <div class="p-0 goods-spec-names clearfix" style="">

                    <!--已选中的默认规格，为span添加 selected样式-->
                    @foreach($pro_val_list as $prop)
                    <span class="spec-values-item selected">
                          <label>
                             <input type="checkbox" class="minimal"
                                {{isset($property_list)?filter_property_selected($prop['props_id'],$property_list):''}}
                             >
                             <span class="_property-name">{{$prop['prop_name']}}</span>
                           </label>
                    </span>
                    @endforeach
                </div>
            </div>
        </div>

        <!--属性规格值选择列表开始-->
        <div id="dropzone" class="ui-sortable goods-spec-items ui-droppable">
            @foreach($pro_val_list as $k => $prop)
            <div class="simple-form-field goods-spec-item drop-item ui-sortable-handle" data-spec-id="1" style="display:{{ isset($property_list)?filter_property_selected($prop['props_id'],$property_list,'block','none'):'none'}}">
                <input type="hidden" name="spec_alias[0][attr_id]" value="162">

                <div class="form-group spec-id-162 clearfix" data-spec-id="162" data-spec-name="颜色">
                    <!-- 规格名称 -->
                    <label class="text-right col-sm-2 fl control-label spec-name cur-p" data-spec-id="162">

                        <!-- 设置规格别名 start-->
                        <span class="form-control-xs text-r w70 spec-name noborder">{{$prop['prop_name']}}</span>
                    </label>
                    <!-- 规格值列表 -->
                    <div class="col-sm-9 fl spec-values" data-spec-id="162">
                        @foreach($prop['val_list'] as $val)
                        <label>
                            <input type="checkbox" class="minimal"
                                   {{isset($property_list)?filter_proval_selected($prop['props_id'],$val['props_value_id'],$property_list):''}}
                                   data-attr-id="{{$prop['props_id']}}"
                                   data-vid="{{$val['props_value_id']}}"
                                   data-vname="{{$val['val_name']}}"
                                   data-attr-name="{{$prop['prop_name']}}" class="spec-value" aria-invalid="false">
                            <span class="_property-name">{{$val['val_name']}}</span>
                        </label>
                        @endforeach
                        {{--<label class="control-label text-l cur-p w100" title="银色">--}}
                            {{--<!-- 选中规格 -->--}}
                            {{--<div class="checker"><span class="checked"><input checked="" type="checkbox" value="2" data-attr-id="1" data-vid="2" data-vname="银色" data-attr-name="颜色" class="spec-value" aria-invalid="false"></span></div>--}}
                            {{--银色                                &nbsp; &nbsp;--}}
                        {{--</label>--}}
                        {{--<label class="control-label text-l cur-p w100" title="黑色">--}}
                            {{--<!-- 选中规格 -->--}}
                            {{--<div class="checker"><span><input type="checkbox" value="3" data-attr-id="1" data-vid="3" data-vname="黑色" data-attr-name="颜色" class="spec-value" aria-invalid="false"></span></div>--}}
                            {{--黑色                                &nbsp; &nbsp;--}}
                        {{--</label>--}}
                    </div>
                </div>
            </div>
            @endforeach
        </div><!--属性规格值选择列表结束-->

        <!--选择生成的商品属性的sku table 开始-->
        <div id="sku_table_container" class="table-responsive" style="overflow: visible;">

            <!--添加商品sku_id-->
            @if(isset($product_id_arr))
                @foreach($product_id_arr as $sku_id)
                <input type="hidden" name="sku_id[]" value="{{$sku_id}}">
                @endforeach
            @endif

            <table id="sku_table" class="table table-hover">
                <thead>
                <tr>
                    <th class="sku-th-index">序号</th>

                    <!--遍历商品的属性-->
                    @if(isset($property_list))
                        @foreach($property_list as $pros_id => $props_val)
                    <th class="spec-th th_spec_id_{{$pros_id}}">{{$props_val['props_name']}}</th>
                        @endforeach
                    @endif
                    <th class="sku-market-price-td ">
                        <span class="text-danger ng-binding">*</span>
                        价格
                        <div class="batch">
                            <a href="javascript:void(0);" class="batch-edit" title="批量设置">
                                <i class="fa fa-edit"></i>
                            </a>
                            <div class="batch-input" style="display: none;">
                                <h6>批量设置价格：</h6>
                                <a href="javascript:void(0);" class="batch-close">X</a>
                                <input type="text" class="form-control text small pull-none valid" value="" aria-invalid="false">
                                <input type="button" class="btn btn-primary btn-sm pull-none m-l-5 btn_batch_set" data-field="market_price" value="设置">
                                <span class="arrow"></span>
                            </div>
                        </div>
                    </th>
                    <th class="sku-goods-price-td ">
                        <span class="text-danger ng-binding">*</span>
                        折扣价
                        <div class="batch">
                            <a href="javascript:void(0);" class="batch-edit" title="批量设置">
                                <i class="fa fa-edit"></i>
                            </a>
                            <div class="batch-input" style="display: none;">
                                <h6>批量设置折扣价：</h6>
                                <a href="javascript:void(0);" class="batch-close">X</a>
                                <input class="form-control text small pull-none valid" type="text" value="" aria-invalid="false">
                                <input type="button" class="btn btn-primary btn-sm pull-none m-l-5 btn_batch_set" data-field="goods_price" value="设置">
                                <span class="arrow"></span>
                            </div>
                        </div>
                    </th>
                    <th>
                        <span class="text-danger ng-binding">*</span>
                        库存
                        <div class="batch">
                            <a href="javascript:void(0);" class="batch-edit" title="批量设置">
                                <i class="fa fa-edit"></i>
                            </a>
                            <div class="batch-input" style="display: none;">
                                <h6>批量设置库存：</h6>
                                <a href="javascript:void(0);" class="batch-close">X</a>
                                <input class="form-control text small pull-none" type="text" value="">
                                <input type="button" class="btn btn-primary btn-sm pull-none m-l-5 btn_batch_set" data-field="goods_number" value="设置">
                                <span class="arrow"></span>
                            </div>
                        </div>
                    </th>
                    <th>
                        商品货号
                        <div class="batch">
                            <a href="javascript:void(0);" class="batch-edit" title="批量设置">
                                <i class="fa fa-edit"></i>
                            </a>
                            <div class="batch-input" style="display: none;">
                                <h6>批量设置商品货号：</h6>
                                <a href="javascript:void(0);" class="batch-close">X</a>
                                <input class="form-control text small pull-none" type="text" value="">
                                <input type="button" class="btn btn-primary btn-sm pull-none m-l-5 btn_batch_set" data-field="warn_number" value="设置">
                                <span class="arrow"></span>
                            </div>
                        </div>
                    </th>
                </tr>
                </thead>
                <tbody>

                <!--遍历一行规格-->
                @if(isset($sku_list))
                    @foreach($sku_list as $table_row => $sku)
                <tr>
                    <td class="sku-td-index text-c">1<a class="del-btn sku-item-handle" data-sku-enable="false" data-sku-index="1" title="点击禁用此规格"></a></td>
                    <!--遍历每条属性属性值-->
                    @foreach($sku['sku_prop_list'] as $k => $property)
                        <?php //dd($property)?>
                    <td class="spec-vname-td">
                        <span class="spec-vname-label spec-vname-label-1073" data-attr-id="162">{{$property->props_value_name}}</span>
                        <input type="hidden" name="specs[{{$table_row}}][{{$property->props_id}}][attr_id]" value="{{$property->props_id}}">
                        <input type="hidden" name="specs[{{$table_row}}][{{$property->props_id}}][attr_vid]" value="{{$property->props_value_id}}" class="spec-vid-text-1073" data-attr-id="162">
                        <input type="hidden" name="specs[{{$table_row}}][{{$property->props_id}}][attr_vname]" value="{{$property->props_value_name}}" class="spec-vname-text-1073" data-attr-id="162">
                        <input type="hidden" name="specs[{{$table_row}}][{{$property->props_id}}][attr_desc]" value="" class="spec-desc-text-1073" data-attr-id="162">
                        <input type="hidden" name="specs[{{$table_row}}][{{$property->props_id}}][disabled]" value="false">
                    </td>
                    @endforeach
                    <td class="sku-market-price-td ">
                        <input data-msg-required="市场价不能为空" data-rule-required="true" type="text" name="sku[{{$table_row}}][price]" value="{{$sku['sku']['price']}}" class="form-control w60 sku-field sku-market-price" data-rule-min="0.01" data-msg-min="市场价必须是大于0的数字" aria-required="true">
                    </td>
                    <td class="sku-goods-price-td ">
                        <input type="text" name="sku[{{$table_row}}][discount_money]" value="{{$sku['sku']['discount_price']==0.00?'':$sku['sku']['discount_price']}}" class="form-control w60 sku-field sku-goods-price" data-rule-required="false" data-msg-required="折扣价不能为空" data-rule-min="0" data-msg-min="折扣价必须是大于等于0的数字" data-msg-decimal="折扣价必须是一个数字" aria-required="true">
                    </td>
                    <td>
                        <input type="text" name="sku[{{$table_row}}][store]" value="{{$sku['sku']['stock']}}" class="form-control small sku-field sku-goods-number" data-rule-required="true" data-msg-required="库存不能为空" data-rule-min="0" data-msg-min="库存必须大于等于0" aria-required="true">
                    </td>
                    <td>
                        <input type="text" name="sku[{{$table_row}}][bn]" value="{{$sku['sku']['bn']}}" class="form-control small sku-field sku-goods-number" data-rule-required="true" data-msg-required="货号不能为空" aria-required="true">
                        <input type="hidden" name="sku[{{$table_row}}][sku_id]" value="{{$sku['sku']['product_id']}}">
                    </td>
                </tr>
                    @endforeach
                @endif
                </tbody>
            </table>

        </div><!--选择生成的商品属性的sku table结束-->

        <!-- 规格数量大于1则发出警告提示 -->
        <p id="sku_table_warning" class="form-control-warning m-t-10" style="display: block;">
            <i class="fa fa-exclamation-circle"></i>
            <span>1.设置默认规格后，才可以编辑商品的相册图片。</span>
            <span>2.您需要选择至少一个商品规格，才能组合成完整的规格信息。</span>
        </p>

    </div>

</div>